package net.melon.cata.manager;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

import net.esj.basic.core.engine.factory.bean.BeanFactory;
import net.melon.cata.pojo.Catalog;

@Singleton
@Named
public class CatalogServiceFactory {

	BeanFactory beanFactory;

	@Inject
	public void setBeanFactory(BeanFactory beanFactory) {
		this.beanFactory = beanFactory;
	}
	
	public CatalogService getService(String name){
		Object o = beanFactory.getBean(name);
		if(o!=null && o instanceof CatalogService){
			return (CatalogService) o;
		}
		return null;
	}
	
	public CatalogService getService(Class clazz){
		String clazzName = clazz.getSimpleName();
		Object o = beanFactory.getBean(clazzName+Catalog.CATALOG_SERVICE_POSTFIX);
		if(o!=null && o instanceof CatalogService){
			return (CatalogService) o;
		}
		return null;
	}
}
